<?php
require_once "includes/config.php";
require_once "includes/functions.php";

require_once 'includes/class.phpmailer.php';
session_start();

if($_POST)
{
if($_POST['type']=="job")
{
mysql_query("insert into tbl_messages(senderid,recieverid,productid,subject,message,posteddate,status,section) values('".$_SESSION['user_id_sess']."','".$_POST['recieverid']."','".$_POST['jobid']."','".$_POST['txtSub']."','".$_POST['txtQuery']."','".date("Y-m-d")."','1','Job')");
$emailContent="Subject: ".$_POST['txtSub']."<br>";
$emailContent.="Query: ".$_POST['txtQuery']."<br>";
}
else
{
$emailContent="You are receiving this message because (".$_SESSION['user_name'].") has sent you message towards (<a href=index.php?products=".$_POST['productid'].">".$_POST['productname']."</a>)<p>Message:".$_POST['txtQuery']."</p>";
mysql_query("insert into tbl_messages(senderid,recieverid,productid,subject,message,posteddate,status) values('".$_SESSION['user_id_sess']."','".$_POST['recieverid']."','".$_POST['productid']."','".$_POST['txtSub']."','".$emailContent."','".date("Y-m-d")."','1')");
}


 $mailmsg="<table width='100%' border='0' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px; line-height:25px'>
 
  <tr>
    <td height='32' colspan='2' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;'>".$emailContent."</td>
  </tr>
  
 
</table>
";
		$mail = new PHPMailer(); // defaults to using php "mail()"
	  	$mail->MsgHTML($mailmsg);
		$mail->From       = "mail@swapen.com";
		$mail->FromName   = "Swapen.com";
		$mail->Subject    = "Suggestion Mail";
		//$mail->AddAddress("suggestions@swapen.com", $firstName);
		//$mail->Send();
		$_SESSION['msg']="Messege sent successfully";
}

?>
<link href="js/spry/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<link href="includes/style.css" rel="stylesheet" type="text/css" />
<title>Swapen.com</title><div id='panel'>
<table width="100%" border="0">
  <tr>
    <td align="center" class="errorField"><?php echo $_SESSION['msg'];$_SESSION['msg']="";?></td>
  </tr>
  
  <tr>
    <td><form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
      <table width="100%" border="0" cellpadding="5" cellspacing="3" class="boldGreyNotes">
        <tr>
          <td width="16%">Subject</td>
          <td width="24%"><input name="txtSub" type="text" id="txtSub" /></td>
          <td width="12%">&nbsp;</td>
          <td width="48%">&nbsp;</td>
        </tr>
        <tr>
          <td>Your Message </td>
          <td colspan="3"><textarea name="txtQuery" cols="40" rows="5" id="txtQuery"></textarea></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td colspan="3"><input type="submit" name="Submit" value="Send Message" />
            <input type="button" name="Submit2" value="Close Window" onclick="window.close();"/>
            <input type="hidden" name="recieverid" value="<?php echo $_REQUEST['ownerid'];?>"/>
            <input type="hidden" name="productid" value="<?php echo $_REQUEST['productid'];?>"/>
			<input type="hidden" name="productname" value="<?php echo $_REQUEST['productname'];?>"/>
			<input type="hidden" name="jobid" value="<?php echo $_REQUEST['jobid'];?>"/>
			<input type="hidden" name="type" value="<?php echo $_REQUEST['type'];?>"/>
			</td>
        </tr>
      </table>
        </form>    </td>
  </tr>
</table>
</div>
